#pragma once

#include "Token.h"
#include <vector>
#include <string>
#include <unordered_map>
#include <memory>

namespace MiniDB
{

    class Lexer
    {
    public:
        explicit Lexer(const std::string &sql);
        std::vector<Token> tokenize();
        const std::unordered_map<std::string, TokenType> &getKeywords() const { return keywords_; }

    private:
        std::string sql_;
        std::vector<Token> tokens_;
        size_t position_;
        int line_;
        int column_;
        char current_char_;

        // 关键字映射
        static const std::unordered_map<std::string, TokenType> keywords_;

        void advance();
        char peek() const;
        void skipWhitespace();
        std::string readIdentifier();
        std::string readStringLiteral();
        std::string readNumberLiteral();
        TokenType getKeywordType(const std::string &word) const;
    };

} // namespace MiniDB
